function getUrlParams(url) {
   var params = new Object();
   if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
    	  params[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
   }
   return params;
}
function pageLink(url){
	var params = getUrlParams(url);
	document.QUERYS.page.value = params.page;
	document.QUERYS.submit();
	return false;
}
function getValues(form,name) {
	var el = form[name];
	var ret = new Array();
	if(!el) return '';
	if(el.value && el.checked){
		return el.value;
	}
	for(var i=0;i<el.length;i++) {
		if(el[i].checked){
			ret.push(el[i].value);
		}
	}
	return ret;
}
function onsearchs(url, form){
	url+="&options=";
	var list = ['areatype','pricetype','roomtype','housetype','fitmenttype'];
	if(form['keywords'].value == '请输入房源特征，地点或小区名'){
		form['keywords'].value = '';
	};
	var fel = form.elements;
	for(key in list){
		type = list[key];
		if(fel[type] && fel[type].value != ''){
			url+='opt.';
			url+=type;
			url+='.';
			url+=fel[type].value;
		}
	}
	if(fel['keywords'].value != ''){
		url+="&keywords=";
		url+=fel['keywords'].value;
	}
	window.location.href = url;
	return;
}

function setHandler(url, obj, elname, type, callback){
	if(callback == undefined) callback = ajax.guide;
	var houseids = (typeof(obj) == 'object') ? getValues(obj, elname).toString() : obj;
	url+='&a=ajax&part='+type;
	if(houseids != '') url+= '&houseids='+ houseids
	var msg = (/^\d$/.test(houseids) ? '是否确认删除该房源？' : '确定删除所选择的项?');
	if(houseids != '' && type == 'delete'){
		url+='&a=delete&part='+type+'&houseids='+houseids;
		showDialog('confirm',msg,0,function(){
			ajax.send(url,'',callback);
		});
		return false;
	}
	sendmsg(url);
	
}

function doAndCacle(type,flag){
	var urgent = new Array(new Array('cretr','msgtr'),new Array('pricetr','daytr','totaltr','balancetr'));
	var top = urgent;
	var type = (type = 'urgent') ? urgent : top;
	for(key in type[1]){
		if(getObj(type[1][key])) getObj(type[1][key]).style.display = flag ? '' : 'none';
		if(getObj(type[0][key])) getObj(type[0][key]).style.display = flag ? 'none' : '';
	}
	if (flag == 0) {
		getObj("subtr").innerHTML = '确 认';
	} else {
		getObj("subtr").innerHTML = '确认购买';
	}
}

function reportData(){
	var reason = getObj("reason").value;
	var ifsendmsg = getObj("ifsendmsg").value;
	var data = 'reason='+reason+'&ifsendmsg='+ifsendmsg;
	return data;
}

function addFavorite(url, title) {
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	}
}

function setHomePage(obj,url){
    try{
        obj.style.behavior='url(#default#homepage)';
        obj.setHomePage(url);
    }
    catch(e){
        if(window.netscape){
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }  
            catch (e) { 
                alert("请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");  
            }
            var com = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            com.setCharPref('browser.startup.homepage',url);
            alert("设为首页成功");
         }
    }
}
function HTMLEncode2(str){  
      var s = "";
      if(str.length == 0) return "";
      s    =    str.replace(/&/g,"&amp;");
      s    =    s.replace(/</g,"&lt;");
      s    =    s.replace(/>/g,"&gt;");
      s    =    s.replace(/ /g,"&nbsp;");
      s    =    s.replace(/\'/g,"&#39;");
      s    =    s.replace(/\"/g,"&quot;");
      return   s;  
}  
function HTMLDecode2(str){  
  var s = "";
  if(str.length == 0)   return "";
  s    =    str.replace(/&amp;/g,"&");
  s    =    s.replace(/&lt;/g,"<");
  s    =    s.replace(/&gt;/g,">");
  s    =    s.replace(/&nbsp;/g," ");
  s    =    s.replace(/&#39;/g,"\'");
  s    =    s.replace(/&quot;/g,"\"");
  return   s;  
}
function changeplate(){
	var plate = eval( '(' + ajax.request.responseText + ')' );
	getObj('platetype').length = 0;
	getObj('platetype').options.add(new Option('所有板块',''));
	if(plate.length==0) return;
	for(key in plate){
		getObj('platetype').options.add(new Option(HTMLDecode2(plate[key]),key));
	}
}
function showMenu(flag){
	getObj('housemenu').style.display = flag ? "" : "none";
}
